import pytest
from pytest_yaml_yoyo import my_builtins


############ """平台""" ############

# 登录 requests_session,environ ,这两个形参不能变，否则报错
@pytest.fixture(scope='module')
def plat_login_first(requests_session,environ):
    """全局仅一次登录， 更新session请求头部"""
    json = {
        "phone": environ.phone,
        "code": environ.code
    }
    with requests_session.post(f'{environ.BASE_URL}/login/sms', json=json) as r:
        data = r.json()
        token = data.get("data")
        headers = {
            "Authorization": f"{token}"
        }
        requests_session.headers.update(headers)




############ """商户""" ############

# 登录 requests_session,environ ,这两个形参不能变，否则报错
@pytest.fixture(scope='module')
def mch_login_first(requests_session,environ):
    """全局仅一次登录， 更新session请求头部"""
    json = {
        "phone": environ.phone,
        "code": environ.code
    }
    with requests_session.post(f'{environ.BASE_URL}/login/sms', json=json) as r:
        data = r.json()
        token = data.get("data")
        headers = {
            "Authorization": f"{token}"
        }
        requests_session.headers.update(headers)



# 角色数据权限
def role_perm_list():
    return ['ALL', 'CUR_ORG', 'SUB_ORG', 'ME']


my_builtins.role_perm_list = role_perm_list
